from selenium import webdriver
import time


#自动登录
drive = webdriver.Chrome()
drive.get('https://aregsr.vip/')
drive.find_element_by_id('goin').click()
drive.find_element_by_id('ls_username').send_keys('ggfygg')
drive.find_element_by_id('ls_password').send_keys('fhrAKMv@A4NXLkN')
drive.find_element_by_class_name('mem_login').click()
time.sleep(5)

#selenium保存cookies
import json

cookies = drive.get_cookies()
with open("cookies.txt", "w") as fp:
    json.dump(cookies, fp)

#requests读取cookies
import requests
from requests.cookies import RequestsCookieJar
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

s = requests.session()
s.verify = False
s.headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36"
    }
# s.get("http://www.baidu.com")

#这里我们使用cookie对象进行处理
jar = RequestsCookieJar()
with open("cookies.txt", "r") as fp:
    cookies = json.load(fp)
    for cookie in cookies:
        jar.set(cookie['name'], cookie['value'])

#获取网页
r = s.get("https://aregsr.vip/thread-14813832-1-1.html", cookies=jar)
r.encoding = "utf-8"
print(r.text)